/*
 * $Id$
 */
package corejs.parser;

import corejs.Token;

import corejs.expr.DecrementExpr;
import corejs.expr.Expression;

import corejs.expr.IncrementExpr;

import static corejs.JsTokenType.*;

public class PostfixOperatorParser implements InfixParser {
   
   /**
    *
    * @param parser
    * @param left
    * @param currentToken
    * @return
    */
   public Expression expr(final PrattParser parser, 
                          final Expression left, 
                          final Token currentToken) {
      return currentToken.is(PLUS_PLUS)   ? new IncrementExpr(left, false)
         :   currentToken.is(MINUS_MINUS) ? new DecrementExpr(left, false)
         :                                  error();
   }

   public int getPrecedence() {
      return Precedence.POSTFIX;
   }
   
   private Expression error() {
      throw new SyntaxError();
   }
}
